<template>
	<view>
		<view class="cu-form-group">
			<view class="title">绑定列名:</view>
			<input class="inpt" name="input" placeholder="点击选取列名" disabled data-target="printModal" :value="SaveMDataJson.DataName"
			 @tap="showModal"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">文本内容:</view>
			<input class="inpt" name="input" placeholder="点击输入文本内容" v-model="SaveMDataJson.LabText"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">打印类型:</view>
			<input class="inpt" name="input" placeholder="点击选取打印类型" disabled data-target="TypeModal" :value="SaveMDataJson.PrintType"
			 @tap="showModal"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">序号:</view>
			<input class="inpt" name="input" placeholder="点击输入序号" v-model="SaveMDataJson.RowNum"></input>
		</view>
		<!-- 	<view class="cu-form-group" > 
			<view class="title">行号:</view>
			<input class="inpt"   name="input"  placeholder="点击输入行号"  v-model="SaveMDataJson.LabText"></input>
		</view>  -->
		<view class="cu-form-group">
			<view class="title">间隔:</view>
			<input class="inpt" name="input" placeholder="点击输入间隔" v-model="SaveMDataJson.Y"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">字号大小:</view>
			<input class="inpt" name="input" placeholder="点击输入字号大小" v-model="SaveMDataJson.FontSize"></input>
		</view>
		<view class="cu-form-group" v-if="type==2">
			<view class="title">是否汇总:</view>
			<input class="inpt" name="input" placeholder="点击选择是否汇总" v-model="SaveMDataJson.IsSum" disabled data-target="IsSumModal"  @tap="showModal"></input>
		</view>
		<view class="cu-form-group btsave">
			<button class="stop" @tap="Save_MasterPrintFormat()">保存</button>
		</view>
		<!-- <view class="cu-form-group" >
			<view class="title">字体大小:</view>
			<input class="inpt"  name="input"  placeholder="点击输入字体大小"  v-model="SaveMDataJson.LabText"></input>
		</view> -->
		<view class="cu-modal" :class="modalName=='printModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">请选择列名</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<!-- 					<view class="searchStore">
						<input placeholder="请输入仓库名称" v-model="SearchStoreName" @input="filterStore" />
						<button @tap="searchStore">搜索</button>
					</view> -->
					<view class="StoreListWrap">
						<view v-for="(item,index) in TempStoreList" :key="item.StoreID" @tap="selectStore(index)">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="cu-modal" :class="modalName=='TypeModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">请选择类型</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<view class="StoreListWrap">
						<view v-for="(item,index) in TempTypeList" :key="item.StoreID" @tap="selectType(index)">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="cu-modal" :class="modalName=='IsSumModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">请选择是否汇总</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<view class="StoreListWrap">
						<view v-for="(item,index) in IsSum" :key="index" @tap="selectIsSum(index)">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import printConfig from "@/common/printConfig.js"
	import * as Api from '@/syApis/sySet/sySet.js'
	export default {
		data() {
			return {
				SaveMDataJson: {
					Id: "",
					BillType: "",
					PrinterType: "",
					RowNum: "",
					DataName: "",
					LabText: "",
					PrintType: "",
					FontSize: "",
					BitNum: "",
					IsSum:"否"
				},
				TempStoreList: [],
				TempTypeList: [{
						name: "一维条码"
					},
					{
						name: "二维条码"
					},
					{
						name: "文本"
					},
					{
						name: "线条"
					},
					{
						name: "商品名称"
					}
				],
				IsSum:[{
					name:"是"
				},{
					name:"否"
				}],
				modalName: "",
				type: 0 // 0头部尾部 1中间
			}
		},
		methods: {
			showModal(e) {
				this.modalName = e.target.dataset.target
			},
			selectType(index) {
				this.SaveMDataJson.PrintType = this.TempTypeList[index].name;
				this.modalName = '';
			},
			selectStore(index) {
				this.SaveMDataJson.DataName = this.TempStoreList[index].name;
				this.modalName = '';
			},
			hideModal() {
				this.modalName = '';
			},
			Save_MasterPrintFormat() {
				this.SaveMDataJson.IsSum = this.SaveMDataJson.IsSum == "否"?'false':'true'
				let data = {
					Save_M_Data_Json: JSON.stringify(this.SaveMDataJson)
				}
				// let SaveMDataJson = 
				if(this.type==0){
					Api.Save_MasterPrintFormat(data, function(res) {
						if(res.state){
							if(res.data.ErrorMsg!=""){
								
							}else{
								Api.showTip("新增成功");
							}
						}
					})
				}else if(this.type==1){
					Api.Save_SlavePrintFormat(data, function(res) {
						if(res.state){
							if(res.data.ErrorMsg!=""){
								
							}else{
								Api.showTip("新增成功");
							}
						}
					})
				}else{
					Api.Save_TableFootPrintFormat(data, function(res) {
						if(res.state){
							if(res.data.ErrorMsg!=""){
								
							}else{
								Api.showTip("新增成功");
							}
						}
					})
				}
				
			},
			selectIsSum(index){
				this.SaveMDataJson.IsSum = this.IsSum[index].name;
				this.modalName = "";
				if(this.type==2){
					if(this.SaveMDataJson.IsSum=="否"){
						this.TempStoreList = printConfig.printConfigList[this.SaveMDataJson.BillType - 1].containtCn
					}else{
						this.TempStoreList = printConfig.printConfigList[this.SaveMDataJson.BillType - 1].headerAndFoodCN
					}
				}
			}
		},
		onLoad(options) {
			this.SaveMDataJson.BillType = options.BillType
			this.SaveMDataJson.PrinterType = options.PrinterType
			this.type = options.type
			// this.SaveMDataJson.PrinterType = options.PrinterType
			if (this.type != 0) {
				this.TempStoreList = printConfig.printConfigList[options.BillType - 1].containtCn
			} else {
				this.TempStoreList = printConfig.printConfigList[options.BillType - 1].headerAndFoodCN
			}
			if(this.type==2){
				if(this.SaveMDataJson.IsSum=="否"){
					this.TempStoreList = printConfig.printConfigList[options.BillType - 1].containtCn
				}else{
					this.TempStoreList = printConfig.printConfigList[options.BillType - 1].headerAndFoodCN
				}
			}
			
			if(options.isChange=="0"){
				this.SaveMDataJson = JSON.parse(options.OldData);
			}
			// console.log(this.TempStoreList);
		}
	}
</script>

<style>
	page {
		padding-bottom: 120upx;
	}

	/* 弹框样式 */
	.padding-xl .searchStore {
		display: flex;
		width: 100%;
		margin: auto;
		height: 45px;
		padding-top: 5px;
		font-size: 14px;
	}

	.padding-xl .searchStore input {
		flex: 1;
		height: 35px;
		border: 1px solid #CCC;
		border-top-left-radius: 5px;
		border-bottom-left-radius: 5px;
		padding-left: 10px;
	}

	.padding-xl {
		padding: 10px;

	}

	.padding-xl .searchStore button {
		font-size: 14px;
		color: #FFF;
		padding-left: 8px;
		padding-right: 8px;
		height: 35px;
		line-height: 35px;
		border-radius: 0px;
		border-top-right-radius: 5px;
		border-bottom-right-radius: 5px;
		text-align: center;
		background: rgba(124, 170, 216, 1);
	}

	.padding-xl .StoreListWrap {
		height: 250px;
		overflow: auto;
	}

	.padding-xl .StoreListWrap view {
		height: 40px;
		line-height: 40px;
		text-align: left;
		border-bottom: 1px solid #CCC;
		padding-left: 8px;
	}

	.cu-form-group {
		padding: 1px 10px !important;
		height: 40px;
		line-height: 40px;
		min-height: 40px;
	}

	/* 表头 */
	.tabHeader {
		width: 100%;
		height: 200px;
		overflow: hidden;
		position: relative;
		padding-bottom: 40px;
	}

	.tabHeader.tabHeaderMore {
		width: 100%;
		display: table;
	}

	.inpt1 {
		text-align: left;
	}

	.btsave {
		width: 100%;
		height: 100upx;
		line-height: 100upx;
		position: fixed;
		bottom: 1upx;
	}

	.btsave button {
		width: 96%;
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		background: #7CAAD8;
		color: #FFF;
	}
</style>
